<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="maName">
        <el-input
          v-model="queryParams.maName"
          placeholder="请输入姓名"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="maGender">
        <el-input
          v-model="queryParams.maGender"
          placeholder="请输入性别"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学号" prop="studentId">
        <el-input
          v-model="queryParams.studentId"
          placeholder="请输入学号"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="班级" prop="meClass">
        <el-input
          v-model="queryParams.meClass"
          placeholder="请输入班级"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="现任职务" prop="curPosition">
        <el-input
          v-model="queryParams.curPosition"
          placeholder="请输入现任职务"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请入团时间" prop="appDate">
        <el-date-picker clearable
          v-model="queryParams.appDate"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择申请入团时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="确立为入团积极分子时间" prop="estDate">
        <el-date-picker clearable
          v-model="queryParams.estDate"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择确立为入团积极分子时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="上次综评" prop="lastEvaluation">
        <el-input
          v-model="queryParams.lastEvaluation"
          placeholder="请输入上次综评"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="辅导员" prop="nmdCounselor">
        <el-input
          v-model="queryParams.nmdCounselor"
          placeholder="请输入辅导员"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核状态" prop="auditStatus">
        <el-select v-model="queryParams.auditStatus" placeholder="请选择审核状态" clearable>
          <el-option
            v-for="dict in ${dictType}"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="未通过原因" prop="rejectionReason">
        <el-input
          v-model="queryParams.rejectionReason"
          placeholder="请输入未通过原因"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="确立年份" prop="establishmentYear">
        <el-date-picker clearable
          v-model="queryParams.establishmentYear"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择确立年份">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="用户ID" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入用户ID"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部门id" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入部门id"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
          v-hasPermi="['active1:active1:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="Edit"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['active1:active1:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="Delete"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['active1:active1:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['active1:active1:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="active1List" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="maId" />
      <el-table-column label="姓名" align="center" prop="maName">
        <template #default="scope">
          <dict-tag :options="${column.dictType}" :value="scope.row.maName"/>
        </template>
      </el-table-column>
      <el-table-column label="性别" align="center" prop="maGender">
        <template #default="scope">
          <dict-tag :options="${column.dictType}" :value="scope.row.maGender"/>
        </template>
      </el-table-column>
      <el-table-column label="学号" align="center" prop="studentId">
        <template #default="scope">
          <dict-tag :options="${column.dictType}" :value="scope.row.studentId"/>
        </template>
      </el-table-column>
      <el-table-column label="班级" align="center" prop="meClass">
        <template #default="scope">
          <dict-tag :options="${column.dictType}" :value="scope.row.meClass"/>
        </template>
      </el-table-column>
      <el-table-column label="现任职务" align="center" prop="curPosition">
        <template #default="scope">
          <dict-tag :options="${column.dictType}" :value="scope.row.curPosition"/>
        </template>
      </el-table-column>
      <el-table-column label="申请入团时间" align="center" prop="appDate" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.appDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="确立为入团积极分子时间" align="center" prop="estDate" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.estDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="上次综评" align="center" prop="lastEvaluation">
        <template #default="scope">
          <dict-tag :options="${column.dictType}" :value="scope.row.lastEvaluation"/>
        </template>
      </el-table-column>
      <el-table-column label="辅导员" align="center" prop="nmdCounselor">
        <template #default="scope">
          <dict-tag :options="${column.dictType}" :value="scope.row.nmdCounselor"/>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="auditStatus">
        <template #default="scope">
          <dict-tag :options="${column.dictType}" :value="scope.row.auditStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="未通过原因" align="center" prop="rejectionReason">
        <template #default="scope">
          <dict-tag :options="${column.dictType}" :value="scope.row.rejectionReason"/>
        </template>
      </el-table-column>
      <el-table-column label="确立年份" align="center" prop="establishmentYear" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.establishmentYear, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="用户ID" align="center" prop="userId">
        <template #default="scope">
          <dict-tag :options="${column.dictType}" :value="scope.row.userId"/>
        </template>
      </el-table-column>
      <el-table-column label="部门id" align="center" prop="deptId">
        <template #default="scope">
          <dict-tag :options="${column.dictType}" :value="scope.row.deptId"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['active1:active1:edit']">修改</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['active1:active1:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改入团积极分子对话框 -->
    <el-dialog :title="title" v-model="open" width="500px" append-to-body>
      <el-form ref="active1Ref" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="姓名" prop="maName">
          <el-input v-model="form.maName" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="性别" prop="maGender">
          <el-input v-model="form.maGender" placeholder="请输入性别" />
        </el-form-item>
        <el-form-item label="学号" prop="studentId">
          <el-input v-model="form.studentId" placeholder="请输入学号" />
        </el-form-item>
        <el-form-item label="班级" prop="meClass">
          <el-input v-model="form.meClass" placeholder="请输入班级" />
        </el-form-item>
        <el-form-item label="现任职务" prop="curPosition">
          <el-input v-model="form.curPosition" placeholder="请输入现任职务" />
        </el-form-item>
        <el-form-item label="申请入团时间" prop="appDate">
          <el-date-picker clearable
            v-model="form.appDate"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择申请入团时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="确立为入团积极分子时间" prop="estDate">
          <el-date-picker clearable
            v-model="form.estDate"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择确立为入团积极分子时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="上次综评" prop="lastEvaluation">
          <el-input v-model="form.lastEvaluation" placeholder="请输入上次综评" />
        </el-form-item>
        <el-form-item label="辅导员" prop="nmdCounselor">
          <el-input v-model="form.nmdCounselor" placeholder="请输入辅导员" />
        </el-form-item>
        <el-form-item label="审核状态" prop="auditStatus">
          <el-radio-group v-model="form.auditStatus">
            <el-radio
              v-for="dict in ${dictType}"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="未通过原因" prop="rejectionReason">
          <el-input v-model="form.rejectionReason" placeholder="请输入未通过原因" />
        </el-form-item>
        <el-form-item label="确立年份" prop="establishmentYear">
          <el-date-picker clearable
            v-model="form.establishmentYear"
            type="date"
            value-format="YYYY-MM-DD"
            placeholder="请选择确立年份">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="用户ID" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户ID" />
        </el-form-item>
        <el-form-item label="部门id" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入部门id" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Active1">
import { listActive1, getActive1, delActive1, addActive1, updateActive1 } from "@/api/active1/active1";

const { proxy } = getCurrentInstance();

const active1List = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    maName: null,
    maGender: null,
    studentId: null,
    meClass: null,
    curPosition: null,
    appDate: null,
    estDate: null,
    lastEvaluation: null,
    nmdCounselor: null,
    auditStatus: null,
    rejectionReason: null,
    establishmentYear: null,
    userId: null,
    deptId: null,
  },
  rules: {
    userId: [
      { required: true, message: "用户ID不能为空", trigger: "blur" }
    ],
    deptId: [
      { required: true, message: "部门id不能为空", trigger: "blur" }
    ],
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询入团积极分子列表 */
function getList() {
  loading.value = true;
  listActive1(queryParams.value).then(response => {
    active1List.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    maId: null,
    maName: null,
    maGender: null,
    studentId: null,
    meClass: null,
    curPosition: null,
    appDate: null,
    estDate: null,
    lastEvaluation: null,
    nmdCounselor: null,
    auditStatus: null,
    rejectionReason: null,
    establishmentYear: null,
    userId: null,
    deptId: null,
    updateTime: null
  };
  proxy.resetForm("active1Ref");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.maId);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加入团积极分子";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const _maId = row.maId || ids.value
  getActive1(_maId).then(response => {
    form.value = response.data;
    open.value = true;
    title.value = "修改入团积极分子";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["active1Ref"].validate(valid => {
    if (valid) {
      if (form.value.maId != null) {
        updateActive1(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addActive1(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _maIds = row.maId || ids.value;
  proxy.$modal.confirm('是否确认删除入团积极分子编号为"' + _maIds + '"的数据项？').then(function() {
    return delActive1(_maIds);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('active1/active1/export', {
    ...queryParams.value
  }, `active1_${new Date().getTime()}.xlsx`)
}

getList();
</script>
